<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/static/common/taglib.jsp" %>
<%@include file="../../public/commonJs.jsp" %>
<%@include file="../../public/commonCss.jsp" %>
<div id="myform" style="background-color: #fff">
    <form class="layui-form">
        <input type="hidden" value="${cd.id}" name="id"/>
        <input type="hidden" value="${cd.codeId}" name="codeId" id="codeId"/>
        <div style="width:100%;height:100%;overflow:hidden;background-color: #fff;">
            <table class="layui-table" lay-skin="nob">
                <tbody>
                <tr>
                    <td width="100" align="right" class="font14"><span class="fontRed">*</span><span id='cc'>代号</span>:
                    </td>
                    <td width="200">
                        <input type="text" name="itemValue" class="layui-input" lay-verify="required"
                               placeholder="请输入代号" value="${cd.itemValue}"/>
                    </td>
                    <td width="50"><span class="font999"></span></td>
                </tr>
                <tr>
                    <td width="100" align="right" class="font14"><span class="fontRed">*</span><span id='vv'>显示值</span>:
                    </td>
                    <td width="200">
                        <input type="text" name="itemText" class="layui-input" lay-verify="required"
                               placeholder="请输入显示文本" value="${cd.itemText}"/>
                    </td>
                    <td width="50"><span class="font999"></span></td>
                </tr>
                <tr>
                    <td width="100" align="right" class="font14"><span class="fontRed"></span>描述:</td>
                    <td width="200"><input type="text" name="describtion" class="layui-input" placeholder="描述"
                                           value="${cd.describtion}"/></td>
                    <td width="50"><span class="font999"></span></td>
                </tr>
                </tbody>
            </table>
            <!-- content -->
            <div class="bottomButton moveArea" style="display:block;position:absolute;bottom:0;">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">保存</button>
                <button class="layui-btn layui-btn-primary" onclick="closeLayer()">取消</button>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    var form = layui.form();
    $("#codeId").val(parent.vm.$model.codeId);
    //自定义验证规则
    form.verify({
        title: function (value) {
            if (value.length < 5) {
                return '标题至少得5个字符啊';
            }
        },
        pass: [/(.+){6,12}$/, '密码必须6到12位'],
        content: function (value) {
            layedit.sync(editIndex);
        }
    });
    //监听提交
    form.on('submit(demo1)', function (data) {
        //这里执行ajax提交
        $.ajax({
            type: 'post',
            url: '${ctx}/codeController/saveOrUpdateCodeData.action',
            data: data.field,
            dataType: "json",
            timeout: 10000,
            success: function (data) {
                if (data.code == 0) {
                    parent.layer.close(index);
                    parent.layer.msg('保存成功', {icon: 1});
                    parent.loadTableData();
                } else if (data.code == -2) {
                    parent.layer.msg('要保存的字典代号已经存在', {icon: 2});
                } else {
                    parent.top.showErrorMsg("保存失败");
                }
            }
        });
        return false;
    });
    form.render();
    //关闭对话框
    function closeLayer() {
        parent.layer.close(index);
    }
</script>
